#include "IObject.h"

namespace Rz {

IObject::~IObject()
{

}

const TypeInfo* IObject::GetTypeInfoStatic()			
{
	static TypeInfo typeInfo = TypeInfo(true, RZ_STRINGIFY(Rz::IObject), RZ_STRINGIFY(IObject), sizeof(IObject));
	typeInfo.Lock();
	return &typeInfo;
}

const void* IObject::To(Utils::Cryptography::Hash hash) const
{
	if (_bases.size() == 0)
	{
		BuildInheritanceCache();
	}

	auto result = _bases.find(hash);
	return (result != _bases.end() ? (*result).second : nullptr);
}

void* IObject::To(Utils::Cryptography::Hash hash)
{
	if (_bases.size() == 0)
	{
		BuildInheritanceCache();
	}

	auto result = _bases.find(hash);
	return (result != _bases.end() ? (*result).second : nullptr);
}

void IObject::RegisterSubclass(const void* ptr, Utils::Cryptography::Hash hash) const
{
	_bases[hash] = const_cast<void*>(ptr);
}

void IObject::RegisterAllSubclasses() const
{
	RegisterSubclass(static_cast<const void*>(this), IObject::GetTypeInfoStatic()->GetFullClassNameHash());
}

void IObject::BuildInheritanceCache() const
{
	RegisterAllSubclasses();
}

}
